package com.csii.modules.online.cgform.util;

import cn.hutool.core.io.FileUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipUtils {
   public static File zip(List<String> var0, String var1) throws RuntimeException {
      File var2 = FileUtil.touch(var1);
      if (var2 == null) {
         return null;
      } else if (!var2.getName().endsWith(".zip")) {
         return null;
      } else {
         try (FileOutputStream var4 = new FileOutputStream(var2);ZipOutputStream var3 = new ZipOutputStream(var4);){

            Iterator var5 = var0.iterator();

            while(true) {
               File var7;
               do {
                  do {
                     if (!var5.hasNext()) {
                        return var2;
                     }
                     String var6 = (String)var5.next();
                     var6 = URLDecoder.decode(var6, "UTF-8").replace("生成成功：", "");
                     var7 = new File(var6);
                  } while(var7 == null);
               } while(!var7.exists());

               byte[] var8 = new byte[4096];
               String entryName = null;
               if (var7.getAbsolutePath().indexOf("src\\") != -1) {
                  entryName = var7.getAbsolutePath().substring(var7.getAbsolutePath().indexOf("src\\") - 1);
               } else if(var7.getAbsolutePath().indexOf("src/") != -1){
                  entryName = var7.getAbsolutePath().substring(var7.getAbsolutePath().indexOf("src/") - 1);
               }else
                  entryName = var7.getAbsolutePath();

               var3.putNextEntry(new ZipEntry(entryName));

               try(FileInputStream var11 = new FileInputStream(var7)) {
                  int var10;
                  while((var10 = var11.read(var8)) != -1) {
                     var3.write(var8, 0, var10);
                  }
               }
               var3.closeEntry();
               var7.delete();
            }
         } catch (Exception var13) {
            throw new RuntimeException("zipFile error from ZipUtils", var13);
         }
      }
   }

   public static void main(String[] args) {
      List list=new ArrayList<>();
      list.add("D:\\aa.bin");
      list.add("D:\\cc.xls");
      ZipUtils.zip(list,"D:/test.zip");
   }
}
